package com.mdd.admin.controller.jiaz.engineer;

import com.mdd.admin.service.jiaz.IEngineerStoreService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.distribution.*;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.engineer.*;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.common.vo.engineer.EngineerFansInfoVo;
import com.mdd.common.vo.engineer.EngineerFansListedVo;
import com.mdd.common.vo.engineer.EngineerStoreDetailVo;
import com.mdd.common.vo.engineer.EngineerStoreListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/engineer/store")
@Api(tags = "师傅管理")
public class EngineerStoreController {

    @Resource
    IEngineerStoreService engineerStoreService;

    @GetMapping("/list")
    @ApiOperation("师傅商列表")
    public AjaxResult<PageResult<EngineerStoreListedVo>> list(@Validated PageValidate pageValidate, @Validated EngineerStoreSearchValidate searchValidate) {
        PageResult<EngineerStoreListedVo> list = engineerStoreService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @PostMapping("/open")
    @ApiOperation("入驻师傅开通")
    public AjaxResult<Object> open(@Validated @RequestBody EngineerStoreOpenValidate openValidate) {
        engineerStoreService.open(openValidate);
        return AjaxResult.success();
    }

    @PostMapping("/freeze")
    @ApiOperation("冻结师傅")
    public AjaxResult<Object> freeze(@Validated @RequestBody IdValidate idValidate) {
        engineerStoreService.freeze(idValidate.getId());
        return AjaxResult.success();
    }

    @GetMapping("/adjustLevelInfo")
    @ApiOperation("等级调整详情")
    public AjaxResult<DistributionAdjustLevelVo> adjustLevelInfo(@Validated @IDMust() @RequestParam("id") Integer id) {
        DistributionAdjustLevelVo vo = engineerStoreService.adjustLevelInfo(id);
        return AjaxResult.success(vo);
    }

    @PostMapping("/adjustLevel")
    @ApiOperation("等级调整")
    public AjaxResult<Object> adjustLevel(@Validated @RequestBody EngineerAdjustLevelValidate adjustValidate) {
        engineerStoreService.adjustLevel(adjustValidate);
        return AjaxResult.success();
    }

    @GetMapping("/detail")
    @ApiOperation("师傅详情")
    public AjaxResult<EngineerStoreDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        EngineerStoreDetailVo vo = engineerStoreService.detail(id);
        return AjaxResult.success(vo);
    }

    @GetMapping("/fansInfo")
    @ApiOperation("下级详情")
    public AjaxResult<EngineerFansInfoVo> fansInfo(@Validated @IDMust() @RequestParam("id") Integer id) {
        EngineerFansInfoVo vo = engineerStoreService.fansInfo(id);
        return AjaxResult.success(vo);
    }

    @GetMapping("/fansList")
    @ApiOperation("下级列表")
    public AjaxResult<PageResult<EngineerFansListedVo>> fansList(@Validated PageValidate pageValidate, @Validated EngineerFansSearchValidate searchValidate) {
        PageResult<EngineerFansListedVo> list = engineerStoreService.fansList(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @PostMapping("/adjustLeader")
    @ApiOperation("调整上级")
    public AjaxResult<Object> adjustLeader(@Validated @RequestBody EngineerAdjustLeaderValidate adjustValidate) {
        engineerStoreService.adjustLeader(adjustValidate);
        return AjaxResult.success();
    }

    @NotLogin
    @GetMapping("/update")
    @ApiOperation("师傅始化数据")
    public AjaxResult<Object> updateData() {
        engineerStoreService.updateData();
        return AjaxResult.success();
    }

}
